package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 *  攻略文章
 */
@Setter
@Getter
public class StrategyDetail extends BaseDomain{
    public static final int STATE_COMMON = 0;//草稿
    public static final int STATE_RELEASE = 1;//发布
//    public static final int STATE_DISABLE= -1;//禁用

    //标题
    private String title;
    //创建时间
    @JsonFormat(pattern = "yyyy-MM-hh")
    private Date createTime;
    //发布时间
    private Date releaseTime;
    //序号
    private Integer sequence;
    //所属目录
    private StrategyCatalog catalog;
    //封面
    private String coverUrl;
    //状态
    private Boolean state;
    //攻略文章内容
    private StrategyContent strategyContent;

    //点赞数(不用出现在数据库字段中)
    private Integer likeNum;

    //是否已经点赞(不用出现在数据库字段中)
    private boolean like;

    //评论数量
    private int commentNum;

    public String getStateString(){
        return state ? "发布" : "草稿";
    }

    public String getJson(){
        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        map.put("sequence",sequence);
        if (catalog!=null){
            map.put("catalogName",catalog.getName());
            map.put("catalogId",catalog.id);
            map.put("strategyId",catalog.getStrategy().id);
        }
        map.put("state",state);
        return JSON.toJSONString(map);
    }
    

}